import channelReducer from "./modules/channelStore";
import authReducer from "./modules/authStore";
import serverReducer from "./modules/serviceStore";
import musicReducer from "./modules/musicStore";
import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { persistStore, persistReducer } from 'redux-persist';
import storage from "redux-persist/lib/storage";

const rootReducer = combineReducers({
    channel:channelReducer,
    auth:authReducer,
    server:serverReducer,
    music:musicReducer,
})

const persistConfig = {
    key: 'root',
    storage,
    blacklist: ['server']
}

const persistedReducer = persistReducer(persistConfig, rootReducer)



export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch

export const store = configureStore({
    reducer: persistedReducer,
    middleware: (getDefaultMiddleware) => 
        getDefaultMiddleware({
            serializableCheck: false // 禁用序列化检查（Redux Persist 需要）
        })
})

export const persistor = persistStore(store)